package edu.mtu.citizenscience.mushroommapper.model;

import java.util.Date;

import com.openswimsoftware.orm.model.Model;
import com.openswimsoftware.orm.model.annotation.Children;
import com.openswimsoftware.orm.model.list.ModelList;

import android.content.Context;

import edu.mtu.citizenscience.mushroommapper.model.report.ModelImage;

/**
 * @author Corbin Uselton <corbinu@cwuselto@mtu.edu>
 * @copyright (c) 2012 MichiganTech <http://www.mtu.edu>
 * @since 1.0
 * 
 * Model of an report in the app DB
 * has a uploaded indicator, location,
 * mushroom name, note and three photos
 */
public class ModelReport extends Model<ModelReport> {
	// reference var for passing report model id between activities
	public static final String REPORT_ID = "REPORT_ID";
	
	// whether the report has been uploaded or not
	private boolean uploaded;
	// report location
	private double latitude;
	private double longitude;
	// date time the report was made
	private Date date;
	// mushroom name
	private String family;
	private String genus;
	private String species;
	// report note
	private String note;
	
	// report children images
	@Children(modelType = ModelImage.class)
	private ModelList<ModelImage> photos;

	/**
	 * Create the report model
	 * 
	 * @param   context - Context - context for model operations
	 * @return	void
	 */
	public ModelReport(Context context) 
	{
		super(context, ModelReport.class);
	}

	/**
	 * Create the report model
	 * 
	 * @param   context - Context - context for model operations
	 * @param	id - long - the id of the model to load
	 * @return	void
	 */
	public ModelReport(Context context, long id) 
	{
		super(context, ModelReport.class, id);
	}
	
	/**
	 * Get the report is uploaded
	 * 
	 * @param   void
	 * @return	boolean - whether the report was uploaded
	 */
	public boolean getUploaded()
	{
		// make sure the model is loaded
		this.load();
	
		return this.uploaded;
	}
	 
	/**
	 * Set the report is uploaded
	 * 
	 * @param   uploaded - boolean - whether the report was uploaded
	 * @return	void
	 */
	public void setUploaded(boolean uploaded)
	{
		// mark the model as updated
		this.updated = true;
		 
		this.uploaded = uploaded;
	}
	
	/**
	 * Get the report latitude
	 * 
	 * @param   void
	 * @return	double - the report latitude
	 */
	public double getLatitude()
	{
		// make sure the model is loaded
		this.load();
		
		return this.latitude;
	}
	 
	/**
	 * Set the report latitude
	 * 
	 * @param   latitude - double - the report latitude
	 * @return	void
	 */
	public void setLatitude(double latitude)
	{
		// mark the model as updated
		this.updated = true;
		 
		this.latitude = latitude;
	}
	
	/**
	 * Get the report longitude
	 * 
	 * @param   void
	 * @return	double - the report longitude
	 */
	public double getLongitude()
	{
		// make sure the model is loaded
		this.load();
		
		return this.longitude;
	}
	 
	/**
	 * Set the report longitude
	 * 
	 * @param   longitude - double - the report longitude
	 * @return	void
	 */
	public void setLongitude(double longitude)
	{
		// mark the model as updated
		this.updated = true;
		 
		this.longitude = longitude;
	}
	 
	/**
	 * Get the report date-time
	 * 
	 * @param   void
	 * @return	Date - the report date-time
	 */
	public Date getDate()
	{
		// make sure the model is loaded
		this.load();
		
		return this.date;
	}
	 
	/**
	 * Set the report date-time
	 * 
	 * @param   date - Date - the report date-time
	 * @return	void
	 */
	public void setDate(Date date)
	{
		// mark the model as updated
		this.updated = true;
		 
		this.date = date;
	}
	
	/**
	 * Get the report family
	 * 
	 * @param   void
	 * @return	String - the report family
	 */
	public String getFamily() 
	{
		// make sure the model is loaded
		this.load();
		
		return family;
	}
	
	/**
	 * Set the report family
	 * 
	 * @param   family - String - the report family
	 * @return	void
	 */
	public void setFamily(String family) 
	{
		// mark the model as updated
		this.updated = true;
		
		this.family = family;
	}

	/**
	 * Get the report genus
	 * 
	 * @param   void
	 * @return	String - the report genus
	 */
	public String getGenus() 
	{
		// make sure the model is loaded
		this.load();
		
		return genus;
	}

	/**
	 * Set the report genus
	 * 
	 * @param   genus - String - the report genus
	 * @return	void
	 */
	public void setGenus(String genus) 
	{
		// mark the model as updated
		this.updated = true;
		
		this.genus = genus;
	}

	/**
	 * Get the report species
	 * 
	 * @param   void
	 * @return	String - the report species
	 */
	public String getSpecies() 
	{
		// make sure the model is loaded
		this.load();
		
		return species;
	}

	/**
	 * Set the report species
	 * 
	 * @param   species - String - the report species
	 * @return	void
	 */
	public void setSpecies(String species) 
	{
		// mark the model as updated
		this.updated = true;
		
		this.species = species;
	}

	/**
	 * Get the report photo one
	 * 
	 * @param   void
	 * @return	ModelImage - the report photo one
	 */
	public ModelImage getPhotoOne() 
	{
		// make sure the model is loaded
		this.load();
		
		for (ModelImage image : this.photos)
		{
			if (image.getNum() == 1)
			{
				return image;
			}
		}
		
		return new ModelImage(this.context);
	}

	/**
	 * Set the report photo one
	 * 
	 * @param   photoOne - ModelImage - the report photo one
	 * @return	void
	 */
	public void setPhotoOne(ModelImage photoOne) 
	{
		// mark the model as updated
		this.updated = true;
		
		photoOne.setNum(1);
		photoOne.save();
		
		this.load();
	}

	/**
	 * Get the report photo two
	 * 
	 * @param   void
	 * @return	ModelImage - the report photo two
	 */
	public ModelImage getPhotoTwo() 
	{
		// make sure the model is loaded
		this.load();
		
		for (ModelImage image : this.photos)
		{
			if (image.getNum() == 2)
			{
				return image;
			}
		}
		
		return new ModelImage(this.context);
	}

	/**
	 * Set the report photo two
	 * 
	 * @param   photoTwo - ModelImage - the report photo two
	 * @return	void
	 */
	public void setPhotoTwo(ModelImage photoTwo) 
	{
		// mark the model as updated
		this.updated = true;
		
		photoTwo.setNum(2);
		photoTwo.save();
		
		this.load();
	}

	/**
	 * Get the report photo three
	 * 
	 * @param   void
	 * @return	ModelImage - the report photo three
	 */
	public ModelImage getPhotoThree() 
	{
		// make sure the model is loaded
		this.load();
		
		// search for image three
		for (ModelImage image : this.photos)
		{
			if (image.getNum() == 3)
			{
				return image;
			}
		}
		
		return new ModelImage(this.context);
	}

	/**
	 * Set the report photo three
	 * 
	 * @param   photoThree - ModelImage - the report photo three
	 * @return	void
	 */
	public void setPhotoThree(ModelImage photoThree) 
	{
		// mark the model as updated
		this.updated = true;
		
		photoThree.setNum(3);
		photoThree.save();
		
		this.load();
	}

	/**
	 * Get the report note
	 * 
	 * @param   void
	 * @return	String - the report note
	 */
	public String getNote()
	{
		// make sure the model is loaded
		this.load();
		
		return this.note;
	}
	 
	/**
	 * Set the report note
	 * 
	 * @param   note - String - the report note
	 * @return	void
	 */
	public void setNote(String note)
	{
		// mark the model as updated
		this.updated = true;
		
		this.note = note;
	}
	
}
